<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="活动名称" prop="activityName">
        <el-input
          v-model="queryParams.activityName"
          placeholder="请输入活动名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="活动主题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading1" :data="activityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="活动id" align="center" prop="id" />
      <el-table-column label="活动主题" align="center" prop="title" />
      <el-table-column label="活动分类" align="center" prop="activityType" />
      <el-table-column label="提交人" align="center" prop="author" />
      <el-table-column label="提交时间" align="center" prop="authorTime" /> 
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="activityTotal>0"
      :total="activityTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
     <el-table v-loading="loading" :data="candidateList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="介绍" align="center" prop="content" />
      <!-- <el-table-column label="附件地址" align="center" prop="fileUrl" />
      <el-table-column label="图片地址" align="center" prop="imageUrl" /> -->
      <el-table-column label="投票数" align="center" prop="num" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate02(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams02.pageNum"
      :limit.sync="queryParams02.pageSize"
      @pagination="getList"
    />
    </el-dialog>

     <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title2" :visible.sync="open2" width="1000px" append-to-body>
     <el-table v-loading="loading2" :data="candidateList2">
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="用户名" align="center" prop="createUserName" />
    </el-table>
    <pagination
      v-show="activityTotal2>0"
      :total="activityTotal2"
      :page.sync="queryParams03.pageNum"
      :limit.sync="queryParams03.pageSize"
      @pagination="getList3"
    />
    </el-dialog>
  </div>
</template>

<script>
import { listCandidate, getCandidate, delCandidate, addCandidate, updateCandidate,listCandidateOrder } from "@/api/system/candidate";
import { listContent } from '@/api/system/eventsinfo'

export default {
  name: "Candidate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      candidateList: [],

      loading1: false,
      activityTotal: 0,
      // 【请填写功能名称】表格数据
      activityList: [],


      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        content: null,
        createddate: null,
        createdby: null,
        deleted: null,
        fileUrl: null,
        imageUrl: null,
        lastmodifiedby: null,
        lastmodifieddate: null,
        name: null,
        activityId: null,
        infoType: 5
      },

      title2: "人员明细",
      open2: false,
      loading2: false,
      candidateList2: [],
      activityTotal2: 0,
      queryParams03: {
        candidateId: null,
        pageNum: 1,
        pageSize: 10
      },

      queryParams02: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        content: null,
        createddate: null,
        createdby: null,
        deleted: null,
        fileUrl: null,
        imageUrl: null,
        lastmodifiedby: null,
        lastmodifieddate: null,
        name: null,
        activityId: null,
        // infoType: 4
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async handleUpdate02(row){
      console.log('row>' + JSON.stringify(row))
      this.queryParams03.candidateId = row.id
      this.queryParams03.pageNum = 1

      await this.getList3()
      this.open2 = true
    },
    async getList3() {
      this.loading2 = true;
      let res = await listCandidateOrder(this.queryParams03)

      if(res.code == 200) {
        this.candidateList2 = res.rows;
        this.activityTotal2 = res.total;
        this.loading2 = false;
        
      }
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading1 = true;
      listContent(this.queryParams).then(response => {
        this.activityList = response.rows;
        this.activityTotal = response.total;
        this.loading1 = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        content: null,
        createddate: null,
        createdby: null,
        deleted: null,
        fileUrl: null,
        imageUrl: null,
        lastmodifiedby: null,
        lastmodifieddate: null,
        name: null,
        activityId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    }, 
    async getList02() {
      this.loading = true;
      let response = await listCandidate(this.queryParams)
      this.candidateList = response.rows;
      this.total = response.total;
      this.loading = false;
    },


    /** 修改按钮操作 */
    async handleUpdate(row) {
      // this.reset();
      const id = row.id || this.ids

      this.queryParams.activityId = id
      await this.getList02()
      this.open = true
      this.title = "查看投票信息"

      // getCandidate(id).then(response => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = "查看投票信息"
      // });
    }
  }
};
</script>
